package org.yinweichen.llm_dataset_backend.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.Date;

@Data
@Entity
@Table(name = "candidate_answers")
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@IdClass(CandidateAnswerId.class)
public class CandidateAnswer {
    @Id
    private Long id;

    @Id
    private String version;

    @Column(name = "answer", columnDefinition = "TEXT(65535)")
    private String answer;

    @Column(name="author",columnDefinition = "VARCHAR(255)")
    private String author;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name = "src_id", referencedColumnName = "id"),
        @JoinColumn(name = "src_version", referencedColumnName = "version")
    })
    @OnDelete(action = OnDeleteAction.CASCADE)
    private StandardQuestion standardQuestion;

    @Column(name = "update_time",columnDefinition = "DATETIME")
    @LastModifiedDate
    private Date updateTime;
}